package com.ruoyi.system.service.impl;

import java.util.List;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.system.domain.HoDormitoryInfo;
import com.ruoyi.system.domain.HoOccupancyInfo;
import com.ruoyi.system.service.IHoDormitoryInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.HoChangeApplicationMapper;
import com.ruoyi.system.domain.HoChangeApplication;
import com.ruoyi.system.service.IHoChangeApplicationService;
import org.springframework.util.CollectionUtils;

/**
 * 换宿申请Service业务层处理
 *
 * @author ruoyi
 * @date 2025-01-10
 */
@Service
public class HoChangeApplicationServiceImpl implements IHoChangeApplicationService {
    @Autowired
    private HoChangeApplicationMapper hoChangeApplicationMapper;

    @Autowired
    private IHoDormitoryInfoService hoDormitoryInfoService;

    /**
     * 查询换宿申请
     *
     * @param id 换宿申请主键
     * @return 换宿申请
     */
    @Override
    public HoChangeApplication selectHoChangeApplicationById(Long id) {
        return hoChangeApplicationMapper.selectHoChangeApplicationById(id);
    }

    /**
     * 查询换宿申请列表
     *
     * @param hoChangeApplication 换宿申请
     * @return 换宿申请
     */
    @Override
    public List<HoChangeApplication> selectHoChangeApplicationList(HoChangeApplication hoChangeApplication) {
        List<HoChangeApplication> list = hoChangeApplicationMapper.selectHoChangeApplicationList(hoChangeApplication);
        if (!CollectionUtils.isEmpty(list)) {
            for (HoChangeApplication changeApplication : list) {
                if (null != changeApplication.getDormitoryId()) {
                    HoDormitoryInfo hoDormitoryInfo = new HoDormitoryInfo();
                    hoDormitoryInfo.setId(changeApplication.getDormitoryId());
                    List<HoDormitoryInfo> hoDormitoryInfos = hoDormitoryInfoService.queryHoDormitoryInfoList(hoDormitoryInfo);
                    if (!CollectionUtils.isEmpty(hoDormitoryInfos)) {
                        changeApplication.setLabel(hoDormitoryInfos.get(0).getLabel());
                    }
                }
            }
        }
        return list;
    }

    /**
     * 新增换宿申请
     *
     * @param hoChangeApplication 换宿申请
     * @return 结果
     */
    @Override
    public int insertHoChangeApplication(HoChangeApplication hoChangeApplication) {
        hoChangeApplication.setCreateTime(DateUtils.getNowDate());
        return hoChangeApplicationMapper.insertHoChangeApplication(hoChangeApplication);
    }

    /**
     * 修改换宿申请
     *
     * @param hoChangeApplication 换宿申请
     * @return 结果
     */
    @Override
    public int updateHoChangeApplication(HoChangeApplication hoChangeApplication) {
        hoChangeApplication.setUpdateTime(DateUtils.getNowDate());
        return hoChangeApplicationMapper.updateHoChangeApplication(hoChangeApplication);
    }

    /**
     * 批量删除换宿申请
     *
     * @param ids 需要删除的换宿申请主键
     * @return 结果
     */
    @Override
    public int deleteHoChangeApplicationByIds(Long[] ids) {
        return hoChangeApplicationMapper.deleteHoChangeApplicationByIds(ids);
    }

    /**
     * 删除换宿申请信息
     *
     * @param id 换宿申请主键
     * @return 结果
     */
    @Override
    public int deleteHoChangeApplicationById(Long id) {
        return hoChangeApplicationMapper.deleteHoChangeApplicationById(id);
    }
}
